package com.anolesoft.twelveFactory.planManagement.controller;

import com.anolesoft.common.core.web.domain.AjaxResult;
import com.anolesoft.twelveFactory.planManagement.dto.PlanissuedDto;
import com.anolesoft.twelveFactory.planManagement.entity.PlanIssued;
import com.anolesoft.twelveFactory.planManagement.service.PlanIsssuedService;
import com.anolesoft.yr.demo.PageResult;
import com.anolesoft.yr.util.Constants;
import com.anolesoft.yr.util.HttpStatus;
import com.anolesoft.yr.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//计划下达
@RestController
@CrossOrigin
@RequestMapping("/twelveFactory/planIssued")
public class PlanIssuedController {

    @Autowired
    private PlanIsssuedService planIsssuedService;
    /**
     *
     * 上下总面板查询 计划下达
     * @param planissuedDto
     * @return
     */
    @PostMapping(value = "/listPlanIsssued", produces = MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult selectPlanIsssued(@RequestBody PlanissuedDto planissuedDto) {
        PageData<List<PlanIssued>> pageData = planIsssuedService.listPlanIssued(planissuedDto);
        //                                          数据                      每页几条               当前页                     总条数
        PageResult pageResult = new PageResult(pageData.getItems(), planissuedDto.getPageSize(), planissuedDto.getPageNo(), pageData.getTotal());
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE, pageResult);
    }
    // 查询数据库计划下达表的所有考核日期
    @PostMapping(value = "/listPlanIsssued2", produces = MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult selectPlanIsssued2() {
           return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE,this.planIsssuedService.listPlanIssued2());
    }
    /**
     *
     * 上下总面板查询 核对计划
     * @param planissuedDto
     * @return
     */
    @PostMapping(value = "/listToThePlan", produces = MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult selectToThePlan(@RequestBody PlanissuedDto planissuedDto) {
        PageData<List<PlanIssued>> pageData = planIsssuedService.listToThePlan(planissuedDto);
            planissuedDto.setJhzt("待审核");
        //                                          数据                      每页几条               当前页                     总条数
        PageResult pageResult = new PageResult(pageData.getItems(), planissuedDto.getPageSize(), planissuedDto.getPageNo(), pageData.getTotal());
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE, pageResult);
    }
    /**
     *
     * 上下总面板查询 确认计划
     * @param planissuedDto
     * @return
     */
    @PostMapping(value = "/listBayPlan", produces = MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult selectBayPlan(@RequestBody PlanissuedDto planissuedDto) {
        PageData<List<PlanIssued>> pageData = planIsssuedService.listBayPlan(planissuedDto);
        //                                          数据                      每页几条               当前页                     总条数
        PageResult pageResult = new PageResult(pageData.getItems(), planissuedDto.getPageSize(), planissuedDto.getPageNo(), pageData.getTotal());
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE, pageResult);
    }
    /**
     *
     * 下达选中计划 批量修改状态
     * @return
     */
    @PostMapping(value = "/updateState", produces = MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult UpdateState(@RequestBody  List<PlanissuedDto> planissuedDtos) {
        for (int i = 0; i <planissuedDtos.size(); i++) {
            planissuedDtos.get(i).setJhzt("待审核");
        }
        return   new AjaxResult(HttpStatus.SUCCESS, Constants.MODIFY_SUCCESS_MESSAGE, this.planIsssuedService.UpdateState(planissuedDtos));
    }
    /**
     *
     * 确认选中计划 批量修改状态
     * @return
     */
    @ResponseBody
    @PostMapping(value = "/updateState2")
    public AjaxResult UpdateState2(@RequestBody  List<PlanissuedDto> planissuedDtos) {
        for (int i = 0; i <planissuedDtos.size(); i++) {
            planissuedDtos.get(i).setJhzt("审核通过");
        }
        return   new AjaxResult(HttpStatus.SUCCESS, Constants.MODIFY_SUCCESS_MESSAGE, this.planIsssuedService.UpdateState1(planissuedDtos));
    }
    /**
     *
     * 修改
     * @return
     */
    @PostMapping(value = "/update")
    public AjaxResult update(@RequestBody PlanissuedDto planissuedDto) {
        return   new AjaxResult(HttpStatus.SUCCESS, Constants.MODIFY_SUCCESS_MESSAGE, this.planIsssuedService.Update(planissuedDto));
    }
    /**
     *
     * 通过objuid查询 单条信息
     * @return
     */
    @GetMapping(value = "selectById")
    public AjaxResult selectById(String objuid){
        return new AjaxResult(HttpStatus.SUCCESS,Constants.QUERY_SUCCESS_MESSAGE,this.planIsssuedService.selectById(objuid));
    }
}
